﻿<UserControl x:Class="MContracts.View.StageResultsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:converters="clr-namespace:MContracts.Classes.Converters" 
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300" DataContext="{Binding}">

    <UserControl.Resources>

        <Style TargetType="Button" x:Key="ActionButtonStyle">
            <Setter Property="Margin" Value="2"/>
            <Setter Property="Width" Value="24"/>
            <Setter Property="Height" Value="24"/>
        </Style>

        <Style TargetType="TextBox">
            <Setter Property="Validation.ErrorTemplate">
                <Setter.Value >
                    <ControlTemplate>
                        <DockPanel LastChildFill="True">
                            <TextBlock DockPanel.Dock="Right" Foreground="Red" FontSize="12" Margin="2, 0, 0, 0" FontWeight="Bold" ToolTip="{Binding ElementName=adornedPlaceHolder, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}">!</TextBlock>
                            <Border BorderBrush="Red" BorderThickness="1" ToolTip="{Binding ElementName=adornedPlaceHolder, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}">
                                <AdornedElementPlaceholder x:Name="adornedPlaceHolder"></AdornedElementPlaceholder>
                            </Border>
                        </DockPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style TargetType="TextBlock">
            <Setter Property="Validation.ErrorTemplate">
                <Setter.Value >
                    <ControlTemplate>
                        <DockPanel LastChildFill="True">
                            <TextBlock DockPanel.Dock="Right" Foreground="Red" FontSize="12" Margin="2, 0, 0, 0" FontWeight="Bold" ToolTip="{Binding ElementName=adornedPlaceHolder, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}">!</TextBlock>
                            <Border BorderBrush="Red" BorderThickness="1">
                                <AdornedElementPlaceholder x:Name="adornedPlaceHolder"></AdornedElementPlaceholder>
                            </Border>
                        </DockPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style TargetType="Label">
            <Setter Property="Validation.ErrorTemplate">
                <Setter.Value >
                    <ControlTemplate>
                        <DockPanel LastChildFill="True">
                            <TextBlock DockPanel.Dock="Right" Foreground="Red" FontSize="12" Margin="2, 0, 0, 0" FontWeight="Bold" ToolTip="{Binding ElementName=adornedPlaceHolder, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}">!</TextBlock>
                            <Border BorderBrush="Red" BorderThickness="1">
                                <AdornedElementPlaceholder x:Name="adornedPlaceHolder"></AdornedElementPlaceholder>
                            </Border>
                        </DockPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style TargetType="DatePicker">
            <Setter Property="Validation.ErrorTemplate">
                <Setter.Value >
                    <ControlTemplate>
                        <DockPanel LastChildFill="True">
                            <TextBlock DockPanel.Dock="Right" Foreground="Red" FontSize="18" FontWeight="Bold" ToolTip="{Binding ElementName=adornedPlaceHolder, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}">!</TextBlock>
                            <Border BorderBrush="Red" BorderThickness="1">
                                <AdornedElementPlaceholder x:Name="adornedPlaceHolder"></AdornedElementPlaceholder>
                            </Border>
                        </DockPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        
        <converters:RemoveExtraSpaceConverter x:Key="RemoveExtraSpaceConverter1" />
        
    </UserControl.Resources>

    <Expander IsExpanded="{Binding IsMaximized, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"  Background="{StaticResource Expander-Background-Results-Brush}">
        <Expander.Header>
            <WrapPanel>
                <Image Source="/MContracts;component/Resources/money_safe1.png" Width="32"/>
                <Label Content="Результаты"/>
            </WrapPanel>
        </Expander.Header>
        <Expander.Content>
            <Border BorderThickness="4" CornerRadius="4" Padding="2" Background="{StaticResource ResourceKey=Expander-Background-Brush}">
                <StackPanel>
                    <StackPanel>
                        <Label Content="Календарный план" />
                        <ComboBox Margin="3,0,3,0" ItemsSource="{Binding Schedulecontracts}" SelectedItem="{Binding SelectedSchedule, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" Margin="3">
                        <Button ToolTip="Создать результат" Style="{StaticResource ActionButtonStyle}" Command="{Binding CreateResultCommand}">
                            <Image Source="/MContracts;component/Resources/archive_add.png" />
                        </Button>
                        <Button ToolTip="Удалить результат" Margin="3" Style="{StaticResource ActionButtonStyle}" Command="{Binding DeleteResultCommand}">
                            <Image Source="/MContracts;component/Resources/archive_remove.png" />
                        </Button>
                    </StackPanel>
                    
                    <DockPanel LastChildFill="True">


                        <telerik:RadGridView CanUserInsertRows="False" Margin="3" SelectedItem="{Binding SelectedResult, Mode=TwoWay}" 
                                             SelectionMode="Single"  SelectionUnit="FullRow" 
                                             ItemsSource="{Binding Path=ResultsBindingList}" ShowColumnHeaders="True" ShowGroupPanel="True"
                                             RowIndicatorVisibility="Collapsed"  AutoGenerateColumns="False" 
                                             x:Name="ScheduleDataGrid" >
                        <telerik:RadGridView.Columns>

                            <telerik:GridViewDataColumn Width="200" Header="Этап" IsGroupable="True" GroupMemberPath="Stage.Num">
                                <telerik:GridViewDataColumn.CellTemplate>
                                    <DataTemplate>
                                        <DockPanel LastChildFill="True">
                                            <TextBlock Text="{Binding Stage}" TextWrapping="WrapWithOverflow" Margin="2,2,2,2" />
                                        </DockPanel>
                                    </DataTemplate>
                                </telerik:GridViewDataColumn.CellTemplate>
                                    <telerik:GridViewDataColumn.CellEditTemplate>
                                        <DataTemplate>
                                            <ComboBox FontSize="12" SelectionChanged="ComboBox_SelectionChanged" SelectedItem="{Binding Path=DataContext.SelectedResult.Stage, Mode=TwoWay, RelativeSource={RelativeSource AncestorType=UserControl}}"
                                                                    ItemsSource="{Binding Path=DataContext.Stages, RelativeSource={RelativeSource AncestorType=UserControl}}" Margin="2,2,2,2"/>
                                        </DataTemplate>
                                    </telerik:GridViewDataColumn.CellEditTemplate>
                                </telerik:GridViewDataColumn>

                                <telerik:GridViewDataColumn Width="300" Header="Наименование" IsGroupable="False" >
                                    <telerik:GridViewDataColumn.CellTemplate>
                                    <DataTemplate>
                                        <DockPanel LastChildFill="True">
                                                <TextBlock Text="{Binding Mode=OneWay, ValidatesOnDataErrors=True, Converter={StaticResource RemoveExtraSpaceConverter1}, Path=Name, UpdateSourceTrigger=PropertyChanged}" Margin="2,2,2,2" TextWrapping="WrapWithOverflow"/>
                                        </DockPanel>
                                    </DataTemplate>
                                    </telerik:GridViewDataColumn.CellTemplate>

                                    <telerik:GridViewDataColumn.CellEditTemplate>
                                        <DataTemplate>
                                            <DockPanel LastChildFill="True">
                                                <TextBox Text="{Binding Mode=TwoWay, ValidatesOnDataErrors=True, Converter={StaticResource RemoveExtraSpaceConverter1}, Path=Name, UpdateSourceTrigger=PropertyChanged}" Margin="2,2,2,2" TextWrapping="WrapWithOverflow"/>
                                            </DockPanel>
                                        </DataTemplate>
                                    </telerik:GridViewDataColumn.CellEditTemplate>
                                </telerik:GridViewDataColumn>

                                <telerik:GridViewDataColumn Width="Auto" Header="Подвид НТП" IsGroupable="True" GroupMemberPath="Ntpsubview.Name">
                                    <telerik:GridViewDataColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding Ntpsubview, ValidatesOnDataErrors=True}" Margin="2,2,2,2" TextWrapping="WrapWithOverflow"/>
                                        </DataTemplate>
                                    </telerik:GridViewDataColumn.CellTemplate>
                                    <telerik:GridViewDataColumn.CellEditTemplate>
                                        <DataTemplate>
                                          <ComboBox FontSize="12" SelectedItem="{Binding Path=DataContext.SelectedResult.Ntpsubview, Mode=TwoWay, RelativeSource={RelativeSource AncestorType=UserControl}}"
                                                                                 ItemsSource="{Binding Path=DataContext.Ntpsubviews, RelativeSource={RelativeSource AncestorType=UserControl}}" x:Name="TypeComboBox1" Margin="2,2,2,2"/>
                                        </DataTemplate>
                                    </telerik:GridViewDataColumn.CellEditTemplate>
                                </telerik:GridViewDataColumn>

                                <telerik:GridViewDataColumn Header="Тип экономической эффективности" Width="Auto" IsGroupable="True" GroupMemberPath="Economefficiencytype">
                                    <telerik:GridViewDataColumn.CellTemplate>
                                        <DataTemplate>
                                            <Label Content="{Binding Economefficiencytype, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" Margin="2,2,2,2"/>
                                        </DataTemplate>
                                    </telerik:GridViewDataColumn.CellTemplate>
                                    <telerik:GridViewDataColumn.CellEditTemplate>
                                        <DataTemplate>
                                            <ComboBox FontSize="12" SelectedItem="{Binding Path=DataContext.SelectedResult.Economefficiencytype, Mode=TwoWay, RelativeSource={RelativeSource AncestorType=UserControl}}"
                                                                                   ItemsSource="{Binding Path=DataContext.Economefficiencytypes, RelativeSource={RelativeSource AncestorType=UserControl}}" x:Name="TypeComboBox" SelectionChanged="TypeComboBox_SelectionChanged" Margin="2,2,2,2" />
                                        </DataTemplate>
                                    </telerik:GridViewDataColumn.CellEditTemplate>
                                </telerik:GridViewDataColumn>

                                <telerik:GridViewDataColumn Header="Параметры" Width="Auto" IsReadOnly="True" IsGroupable="False">
                                    <telerik:GridViewDataColumn.CellTemplate>
                                    <DataTemplate>
                                        <DataGrid CanUserAddRows="False" SelectionMode="Single" SelectionUnit="FullRow" 
                                                HeadersVisibility="None" AutoGenerateColumns="False" HorizontalScrollBarVisibility="Disabled"
                                                ItemsSource="{Binding ParametersBindingList}" Margin="2,2,2,2" >
                                            <DataGrid.Columns>
                                                <DataGridTextColumn Header="Параметр" Width="2*" IsReadOnly="True" Binding="{Binding Economefficiencyparameter, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"/>
                                                <DataGridTextColumn Header="Значение" Width="*" Binding="{Binding Value, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"/>
                                            </DataGrid.Columns>
                                        </DataGrid>
                                    </DataTemplate>
                                    </telerik:GridViewDataColumn.CellTemplate>
                                </telerik:GridViewDataColumn>
                          </telerik:RadGridView.Columns>
                      </telerik:RadGridView>

                    </DockPanel>
                
                </StackPanel>
                
            </Border>
        </Expander.Content>
    </Expander>
</UserControl>
